package com.ysd.lis.service.samsto.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.ysd.common.Result;
import com.ysd.lis.dto.samsto.SamstoSpecboxDto;
import com.ysd.lis.entity.SysOrgDepartment;
import com.ysd.lis.entity.inv.InvOrderInfo;
import com.ysd.lis.entity.inv.InvOrderReagent;
import com.ysd.lis.entity.inv.InvReagentStock;
import com.ysd.lis.entity.SysUser;
import com.ysd.lis.entity.lab.LabMaininfo;
import com.ysd.lis.entity.lab.LabReqMain;
import com.ysd.lis.entity.samsto.*;
import com.ysd.lis.mapper.samsto.SamstoSpecboxMapper;
import com.ysd.lis.request.LabMaininfoPageDto;
import com.ysd.lis.request.samsto.SamstoSpecboxParam;
import com.ysd.lis.service.lab.LabReqMainService;
import com.ysd.lis.service.samsto.SamstoSpecboxModelService;
import com.ysd.lis.service.samsto.SamstoSpecboxOrderService;
import com.ysd.lis.service.samsto.SamstoSpecboxService;
import com.ysd.util.RedisUserManager;
import com.ysd.util.ToolsUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.sql.Timestamp;
import java.util.*;

/**
 * 标本盒表(SamstoSpecbox)表服务实现类
 *
 * @author leiming
 * @since 2024-10-28 18:01:09
 */
@Service("samstoSpecboxService")
public class SamstoSpecboxServiceImpl extends ServiceImpl<SamstoSpecboxMapper, SamstoSpecbox> implements SamstoSpecboxService {
    @Autowired
    SamstoSpecboxOrderService specboxOrderService;
    @Autowired
    SamstoSpecboxModelService specboxModelService;

    @Autowired
    LabReqMainService labReqMainService;

    private MPJLambdaWrapper<SamstoSpecbox> initWrapper() {
        MPJLambdaWrapper<SamstoSpecbox> lambdaQueryWrapper = new MPJLambdaWrapper<>();
        //ID
        lambdaQueryWrapper.selectAs(SamstoSpecbox::getId, SamstoSpecboxDto::getId);
        //编号
        lambdaQueryWrapper.selectAs(SamstoSpecbox::getSpecboxCode, SamstoSpecboxDto::getSpecboxCode);
        //条码号
        lambdaQueryWrapper.selectAs(SamstoSpecbox::getSpecboxBarcode, SamstoSpecboxDto::getSpecboxBarcode);
        //标本盒型号
        lambdaQueryWrapper.selectAs(SamstoSpecbox::getSepmodId, SamstoSpecboxDto::getSepmodId);
        //当前温度
        lambdaQueryWrapper.selectAs(SamstoSpecbox::getCurrentTemp, SamstoSpecboxDto::getCurrentTemp);
        //使用试管范围
        lambdaQueryWrapper.selectAs(SamstoSpecbox::getTubeTypesUse, SamstoSpecboxDto::getTubeTypesUse);
        //所在层
        lambdaQueryWrapper.selectAs(SamstoSpecbox::getLayerId, SamstoSpecboxDto::getLayerId);
        //所在冰箱
        lambdaQueryWrapper.selectAs(SamstoSpecbox::getFridgeId, SamstoSpecboxDto::getFridgeId);
        //位置排序
        lambdaQueryWrapper.selectAs(SamstoSpecbox::getSpecboxSeq, SamstoSpecboxDto::getSpecboxSeq);
        //机构
        lambdaQueryWrapper.selectAs(SamstoSpecbox::getOrgId, SamstoSpecboxDto::getOrgId);
        //状态
        lambdaQueryWrapper.selectAs(SamstoSpecbox::getStatus, SamstoSpecboxDto::getStatus);
        //所属科室
        lambdaQueryWrapper.selectAs(SamstoSpecbox::getDeptName, SamstoSpecboxDto::getDeptName);
        //删除标记
        lambdaQueryWrapper.selectAs(SamstoSpecbox::getDelFlag, SamstoSpecboxDto::getDelFlag);
        //创建人
        lambdaQueryWrapper.selectAs(SamstoSpecbox::getCreator, SamstoSpecboxDto::getCreator);
        //创建时间
        lambdaQueryWrapper.selectAs(SamstoSpecbox::getCreateTime, SamstoSpecboxDto::getCreateTime);
        //修改人
        lambdaQueryWrapper.selectAs(SamstoSpecbox::getEditor, SamstoSpecboxDto::getEditor);
        //修改时间
        lambdaQueryWrapper.selectAs(SamstoSpecbox::getEditTime, SamstoSpecboxDto::getEditTime);
        //删除时间
        lambdaQueryWrapper.selectAs(SamstoSpecbox::getDelTime, SamstoSpecboxDto::getDelTime);
        return lambdaQueryWrapper;
    }

    @Override
    public Result findLabReqMainByKeepSampleState(LabMaininfoPageDto maininfoPageDto) {
        /*目标数据*/
        List<String> tAimCode = new ArrayList<>();
        if (ToolsUtils.isNotEmpty(maininfoPageDto.getSampleNos())) {
            tAimCode = GetAimCode(maininfoPageDto.getSampleNos());
        }
        MPJLambdaWrapper<LabReqMain> queryWrapper = new MPJLambdaWrapper<>();
        queryWrapper.selectAll(LabReqMain.class);
        queryWrapper.selectCollection(LabMaininfo.class, LabReqMain::getLabMaininfoList);
        queryWrapper.leftJoin(LabMaininfo.class, LabMaininfo::getReqNo, LabMaininfo::getReqNo);
        queryWrapper
                .eq(LabReqMain::getDelFlag, 0)
                .and(p -> p.eq(LabReqMain::getIsStore, 0).or().isNull(LabReqMain::getIsStore))
                .le(LabReqMain::getState, Integer.valueOf(maininfoPageDto.getState()));
        if (ToolsUtils.isNotEmpty(maininfoPageDto.getReqNo())) {
            queryWrapper.eq(LabReqMain::getReqNo, maininfoPageDto.getReqNo());
        }
        if (ToolsUtils.isNotEmpty(maininfoPageDto.getRptGroup())) {
            queryWrapper.eq(LabMaininfo::getRptGroup, maininfoPageDto.getRptGroup());
        }

        if (ToolsUtils.isNotEmpty(maininfoPageDto.getSamplingTimeS()) && ToolsUtils.isNotEmpty(maininfoPageDto.getSamplingTimeE())) {
            queryWrapper.ge(LabMaininfo::getSampleda, new Timestamp(DateUtil.parse(maininfoPageDto.getSamplingTimeS()).getTime()));
            queryWrapper.le(LabMaininfo::getSampleda, new Timestamp(DateUtil.parse(maininfoPageDto.getSamplingTimeE()).getTime()));
        }
        queryWrapper.in(!tAimCode.isEmpty(), LabMaininfo::getSampleNo, tAimCode);
        List<LabReqMain> reqPageList = labReqMainService.selectJoinList(LabReqMain.class, queryWrapper);
        return Result.succ(1, "查询成功", reqPageList);
    }

    /*获取单个标本号*/
    private List<String> GetAimCode(String code) {
        List<String> codes = new ArrayList<>();

        code = code.replace("，", ",");
        code = code.replace("—", "-");

        String[] codeArray = code.split(",");

        for (String c : codeArray) {
            if (!c.contains("-")) {
                codes.add(c);
            } else {
                String[] arr = code.split("-");
                for (int i = Integer.parseInt(arr[0]); i <= Integer.parseInt(arr[1]); i++) {
                    codes.add(i + "");
                }
            }
        }
        return codes;
    }

    @Override
    public Result findPageList(SamstoSpecboxParam pageParam) {
        return this.findListByGId(pageParam);
    }

    @Override
    public Result findListByGId(SamstoSpecboxParam pageParam) {
        MPJLambdaWrapper<SamstoSpecbox> queryWrapper = initWrapper();
        queryWrapper.selectAs(SamstoSpecboxModel::getSpecboxModel, SamstoSpecboxDto::getSpecboxModelName);
        queryWrapper.selectAs(SamstoFridge::getBoxCode, SamstoSpecboxDto::getBoxCode);
        queryWrapper.selectAs(SamstoFridgeLayer::getLayerCode, SamstoSpecboxDto::getLayerCode);
        queryWrapper.selectAs(SysOrgDepartment::getName, SamstoSpecboxDto::getDeptNameer);
        queryWrapper.leftJoin(SamstoSpecboxModel.class, SamstoSpecboxModel::getId, SamstoSpecbox::getSepmodId);
        queryWrapper.leftJoin(SamstoFridge.class, SamstoFridge::getId, SamstoSpecbox::getFridgeId);
        queryWrapper.leftJoin(SamstoFridgeLayer.class, SamstoFridgeLayer::getId, SamstoSpecbox::getLayerId);
        queryWrapper.leftJoin(SysOrgDepartment.class, SysOrgDepartment::getCode, SamstoSpecbox::getDeptName);
        Page<SamstoSpecboxDto> page = new Page<SamstoSpecboxDto>();
        page.setCurrent(pageParam.getPageIndex());
        page.setSize(pageParam.getPageSize());
        queryWrapper.eq(SamstoSpecbox::getDelFlag, 0);
        if (StringUtils.isNotBlank(pageParam.getKeywords())) {
            queryWrapper.and(wrapper -> wrapper.like(SamstoSpecbox::getSpecboxCode, pageParam.getKeywords())
                    .or().like(SamstoSpecbox::getSpecboxBarcode, pageParam.getKeywords()));
        }
        queryWrapper.orderByAsc(SamstoSpecbox::getCreateTime);
        if (StringUtils.isNotBlank(pageParam.getSepmodId())) {
            queryWrapper.eq(SamstoSpecbox::getSepmodId, pageParam.getSepmodId());
        }
        try {
            SysUser sysUser = RedisUserManager.getUser();
            if (ToolsUtils.isNotEmpty(sysUser)) {
                queryWrapper.eq(SamstoSpecbox::getOrgId, sysUser.getOrgId());
            }
            page = this.baseMapper.selectJoinPage(page, SamstoSpecboxDto.class, queryWrapper);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Result.succ(1, "获取信息成功", page);
    }

    @Override
    public Result findAllList(SamstoSpecboxParam pageParam) {
        MPJLambdaWrapper<SamstoSpecbox> queryWrapper = initWrapper();
        queryWrapper.selectAs(SamstoSpecboxModel::getSpecboxModel, SamstoSpecboxDto::getSpecboxModelName);
        queryWrapper.selectAs(SamstoSpecboxModel::getTubeTypesRange, SamstoSpecboxDto::getTubeTypesRange);
        queryWrapper.selectAs(SamstoSpecboxModel::getTempRange, SamstoSpecboxDto::getTempRange);
        queryWrapper.selectAs(SamstoSpecboxModel::getSpecboxArray, SamstoSpecboxDto::getSpecboxArray);
        queryWrapper.selectAs(SamstoSpecboxModel::getOrderNumber, SamstoSpecboxDto::getOrderNumber);
        queryWrapper.selectAs(SamstoSpecboxModel::getSpecboxSize, SamstoSpecboxDto::getSpecboxSize);
        queryWrapper.selectAs(SamstoSpecboxModel::getPurpose, SamstoSpecboxDto::getPurpose);
        queryWrapper.selectAs(SysOrgDepartment::getName, SamstoSpecboxDto::getDeptNameer);
        queryWrapper.leftJoin(SamstoSpecboxModel.class, SamstoSpecboxModel::getId, SamstoSpecbox::getSepmodId);
        queryWrapper.leftJoin(SysOrgDepartment.class, SysOrgDepartment::getCode, SamstoSpecbox::getDeptName);
        Page<SamstoSpecboxDto> page = new Page<SamstoSpecboxDto>();
        page.setCurrent(pageParam.getPageIndex());
        page.setSize(pageParam.getPageSize());
        queryWrapper.eq(SamstoSpecbox::getDelFlag, 0);
        if (StringUtils.isNotBlank(pageParam.getKeywords())) {
            queryWrapper.and(wrapper -> wrapper.like(SamstoSpecbox::getSpecboxCode, pageParam.getKeywords())
                    .or().like(SamstoSpecbox::getSpecboxBarcode, pageParam.getKeywords()));
        }
        queryWrapper.orderByAsc(SamstoSpecbox::getCreateTime);
        if (StringUtils.isNotBlank(pageParam.getSepmodId())) {
            queryWrapper.eq(SamstoSpecbox::getSepmodId, pageParam.getSepmodId());
        }
        try {
            SysUser sysUser = RedisUserManager.getUser();
            if (ToolsUtils.isNotEmpty(sysUser)) {
                queryWrapper.eq(SamstoSpecbox::getOrgId, sysUser.getOrgId());
            }
            page = this.baseMapper.selectJoinPage(page, SamstoSpecboxDto.class, queryWrapper);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Result.succ(1, "获取信息成功", page);
    }

    @Override
    public Result getInfoById(String id) {
        SamstoSpecbox SamstoSpecbox = this.baseMapper.selectById(id);
        return Result.succ(1, "获取信息成功", SamstoSpecbox);
    }

    @Override
    public Result findInfoByCode(SamstoSpecboxParam pageParam) {
        MPJLambdaWrapper<SamstoSpecbox> queryWrapper = initWrapper();
        queryWrapper.selectAs(SamstoSpecboxModel::getSpecboxModel, SamstoSpecboxDto::getSpecboxModelName);
        queryWrapper.selectAs(SamstoSpecboxModel::getTubeTypesRange, SamstoSpecboxDto::getTubeTypesRange);
        queryWrapper.selectAs(SamstoSpecboxModel::getTempRange, SamstoSpecboxDto::getTempRange);
        queryWrapper.selectAs(SamstoSpecboxModel::getSpecboxArray, SamstoSpecboxDto::getSpecboxArray);
        queryWrapper.selectAs(SamstoSpecboxModel::getOrderNumber, SamstoSpecboxDto::getOrderNumber);
        queryWrapper.selectAs(SamstoSpecboxModel::getSpecboxSize, SamstoSpecboxDto::getSpecboxSize);
        queryWrapper.selectAs(SamstoSpecboxModel::getPurpose, SamstoSpecboxDto::getPurpose);
        queryWrapper.leftJoin(SamstoSpecboxModel.class, SamstoSpecboxModel::getId, SamstoSpecbox::getSepmodId);
        if (StringUtils.isNotBlank(pageParam.getKeywords())) {
            queryWrapper.and(wrapper -> wrapper.eq(SamstoSpecbox::getSpecboxCode, pageParam.getKeywords())
                    .or().eq(SamstoSpecbox::getSpecboxBarcode, pageParam.getKeywords()));
        }
        SamstoSpecboxDto samstoSpecbox = this.baseMapper.selectJoinOne(SamstoSpecboxDto.class, queryWrapper);
        samstoSpecbox.setSpecboxOrders(specboxOrderService.findListBySpecboxId(samstoSpecbox.getId()));
        return Result.succ(1, "获取信息成功", samstoSpecbox);
    }

    @Override
    public Result findLabReqMainBySampleState(LabMaininfoPageDto maininfoPageDto) {
        /*目标数据*/
        List<String> tAimCode = new ArrayList<>();
        if (ToolsUtils.isNotEmpty(maininfoPageDto.getSampleNos())) {
            tAimCode = GetAimCode(maininfoPageDto.getSampleNos());
        }

        MPJLambdaWrapper<LabReqMain> queryWrapper = new MPJLambdaWrapper<>();
        queryWrapper.selectAll(LabReqMain.class);
        queryWrapper.distinct();
        queryWrapper.selectAs(SamstoSpecboxOrderReq::getStoragePid, LabReqMain::getStoragePid);
        queryWrapper.selectAs(SamstoSpecboxOrderReq::getStorageId, LabReqMain::getStorageId);
        queryWrapper.selectAs(SamstoSpecboxOrderReq::getFridgeId, LabReqMain::getFridgeId);
        queryWrapper.selectAs(SamstoSpecboxOrderReq::getLayerId, LabReqMain::getLayerId);
        queryWrapper.selectAs(SamstoSpecboxOrderReq::getSpecboxId, LabReqMain::getSpecboxId);
        queryWrapper.selectAs(SamstoSpecboxOrderReq::getSpecboxOrderId, LabReqMain::getSpecboxOrderId);
        queryWrapper.selectAs(SamstoSpecboxOrderReq::getOrderNumber, LabReqMain::getOrderNumber);
        queryWrapper.selectAs(SamstoSpecboxOrderReq::getStoragePname, LabReqMain::getStoragePname);
        queryWrapper.selectAs(SamstoSpecboxOrderReq::getStorageName, LabReqMain::getStorageName);
        queryWrapper.selectAs(SamstoSpecboxOrderReq::getFridgeCode, LabReqMain::getFridgeCode);
        queryWrapper.selectAs(SamstoSpecboxOrderReq::getLayerCode, LabReqMain::getLayerCode);
        queryWrapper.selectAs(SamstoSpecboxOrderReq::getId, LabReqMain::getSamstoSpecboxOrderReqId);
        queryWrapper.selectAs(SamstoSpecboxOrderReq::getStatus,LabReqMain::getStatus);

        // queryWrapper.selectCollection(LabMaininfo.class,LabReqMain::getLabMaininfoList);
        // queryWrapper.selectAssociation(SamstoSpecboxOrderReq.class,LabReqMain::getSamstoSpecboxOrderReq);
        queryWrapper.leftJoin(LabMaininfo.class, LabMaininfo::getReqNo, LabMaininfo::getReqNo);
        queryWrapper.leftJoin(SamstoSpecboxOrderReq.class, p -> p.eq(LabReqMain::getReqNo, SamstoSpecboxOrderReq::getReqNo).eq(SamstoSpecboxOrderReq::getDelFlag, 0));
        queryWrapper.leftJoin(SamstoSpecboxOrder.class, p -> p.eq(SamstoSpecboxOrder::getId, SamstoSpecboxOrderReq::getSpecboxOrderId).eq(SamstoSpecboxOrder::getDelFlag, 0));

        queryWrapper
                .eq(LabReqMain::getDelFlag, 0)
                .eq(LabReqMain::getIsStore, 1)
                .ge(LabReqMain::getState, Integer.valueOf(maininfoPageDto.getState()));
        queryWrapper.and(wrapper -> wrapper.eq(SamstoSpecboxOrderReq::getStatus, 5).or().eq(SamstoSpecboxOrderReq::getStatus, 15));
        if (ToolsUtils.isNotEmpty(maininfoPageDto.getReqNo())) {
            queryWrapper.eq(LabReqMain::getReqNo, maininfoPageDto.getReqNo());
        }
        if (ToolsUtils.isNotEmpty(maininfoPageDto.getRptGroup())) {
            queryWrapper.eq(LabMaininfo::getRptGroup, maininfoPageDto.getRptGroup());
        }

        if (ToolsUtils.isNotEmpty(maininfoPageDto.getPatNa())) {
            queryWrapper.eq(LabMaininfo::getPatNa, maininfoPageDto.getPatNa());
        }

        if (ToolsUtils.isNotEmpty(maininfoPageDto.getSamplingTimeS()) && ToolsUtils.isNotEmpty(maininfoPageDto.getSamplingTimeE())) {
            queryWrapper.ge(LabMaininfo::getSampleda, new Timestamp(DateUtil.parse(maininfoPageDto.getSamplingTimeS()).getTime()));
            queryWrapper.le(LabMaininfo::getSampleda, new Timestamp(DateUtil.parse(maininfoPageDto.getSamplingTimeE()).getTime()));
        }
        queryWrapper.in(!tAimCode.isEmpty(), LabMaininfo::getSampleNo, tAimCode);
        List<LabReqMain> reqPageList = labReqMainService.list(queryWrapper);
        return Result.succ(1, "查询成功", reqPageList);
    }

    @Transactional
    @Override
    public Result add(SamstoSpecboxParam param) {
        SamstoSpecbox info = new SamstoSpecbox();
        try {
            SysUser sysUser = RedisUserManager.getUser();
            if (ToolsUtils.isNotEmpty(sysUser)) {
                param.setCreator(sysUser.getId());
                param.setOrgId(sysUser.getOrgId());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        param.setCreateTime(new Date());
        BeanUtil.copyProperties(param, info);
        info.setDelFlag(0);
        info.setStatus(1);
        this.baseMapper.insert(info);
        this.saveSpecboxOrder(info);
        return Result.succ(1, "添加信息成功", null);
    }

    public void delSpecboxOrderByBoxId(SamstoSpecbox info) {
        LambdaQueryWrapper<SamstoSpecboxOrder> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SamstoSpecboxOrder::getSpecboxId, info.getId());
        specboxOrderService.remove(queryWrapper);
    }

    public void saveSpecboxOrder(SamstoSpecbox info) {
        SamstoSpecboxModel specboxModel = specboxModelService.getById(info.getSepmodId());
        List<SamstoSpecboxOrder> specboxOrders = new ArrayList<>();
        JSONObject jsonObject = JSON.parseObject(specboxModel.getOrderNumber());
        //{N:“1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18”}
        /* String[] obnums=jsonObject.getString("N").split(",");
            int rowcount=9;
            Double rowsqrt=Math.sqrt(obnums.length);
            if(rowsqrt>0){
                rowcount=rowsqrt.intValue();
            }
            int scount=1;
            char orderColumn='A';
            int j=0;

            while (obnums.length>j){
                for (int i = j; i < rowcount; i++) {
                    SamstoSpecboxOrder specboxOrder=new SamstoSpecboxOrder();
                    specboxOrder.setSpecboxId(info.getId());
                    specboxOrder.setCreator(info.getCreator());
                    specboxOrder.setCreateTime(info.getCreateTime());
                    specboxOrder.setDeptName(info.getDeptName());
                    specboxOrder.setOrgId(info.getOrgId());
                    specboxOrder.setDelFlag(0);
                    specboxOrder.setStatus(1);
                    specboxOrder.setEmpty(0);
                    specboxOrder.setOrderRow(Integer.toString(scount));
                    specboxOrder.setOrderColumn(Character.toString(orderColumn));
                    specboxOrder.setOrderNumber(obnums[i]);
                    specboxOrders.add(specboxOrder);
                    j++;
                    orderColumn++;
                    if (j==obnums.length){
                        break;
                    }
                }
                scount++;
                orderColumn='A';
                rowcount=rowcount*2;
            }*/
        //{L:“A,B,C,D,E,F,G”,W:“1,2,3,4,5,6,7”}
        String[] obnumLs = jsonObject.getString("L").split(",");
        String[] obnumWs = jsonObject.getString("W").split(",");
        for (int i = 0; i < obnumWs.length; i++) {
            for (int l = 0; l < obnumLs.length; l++) {
                StringBuilder onLW = new StringBuilder();
                onLW.append(obnumLs[l]);
                onLW.append(obnumWs[i]);
                SamstoSpecboxOrder specboxOrder = new SamstoSpecboxOrder();
                specboxOrder.setSpecboxId(info.getId());
                specboxOrder.setCreator(info.getCreator());
                specboxOrder.setCreateTime(info.getCreateTime());
                specboxOrder.setDeptName(info.getDeptName());
                specboxOrder.setOrgId(info.getOrgId());
                specboxOrder.setDelFlag(0);
                specboxOrder.setStatus(1);
                specboxOrder.setEmpty(0);
                specboxOrder.setOrderRow(obnumWs[i]);
                specboxOrder.setOrderNumber(onLW.toString());
                specboxOrder.setOrderColumn(obnumLs[l]);
                specboxOrders.add(specboxOrder);
            }
        }

        if (specboxOrders.size() > 0) {
            specboxOrderService.saveBatch(specboxOrders);
        }
    }

    //fixme:后面是无法修改的只能停用，临时打开
    @Override
    public Result edit(SamstoSpecboxParam param) {
        SamstoSpecbox infon = new SamstoSpecbox();
        List<String> ids = new ArrayList<>();
        ids.add(param.getId());
        int count = specboxOrderService.getCount(ids);
        if (count > 0) {
            return Result.succ(1, "当前所选择的标本盒内有标本不能做修改！", null);
        }
        Map returnMap = new HashMap();
        SamstoSpecbox info = new SamstoSpecbox();
        try {
            SysUser sysUser = RedisUserManager.getUser();
            if (ToolsUtils.isNotEmpty(sysUser)) {
                param.setEditor(sysUser.getId());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        param.setEditTime(new Date());
        BeanUtil.copyProperties(param, info);
        this.baseMapper.updateById(info);
        //fixme:后面是无法修改的只能停用，临时打开
        //this.delSpecboxOrderByBoxId(info);
        //this.saveSpecboxOrder(info);
        returnMap.put("id", param.getId());
        return Result.succ(1, "修改信息成功", returnMap);
    }

    @Override
    public Result delete(List<String> ids) {
        int count = specboxOrderService.getCount(ids);
        if (count > 0) {
            return Result.succ(1, "当前所选择的标本盒内有标本不能删除！", null);
        }
        Result result;
        try {
            boolean b = this.removeByIds(ids);
            if (b) {
                result = Result.succ(1, "删除成功", null);
            } else {
                result = Result.fail(400, "删除失败", "");
            }
        } catch (Exception e) {
            e.printStackTrace();
            result = Result.fail(400, "删除失败", "");
        }
        return result;
    }

    @Override
    public Result updelete(List<String> ids) {
        int count = specboxOrderService.getCount(ids);
        if (count > 0) {
            return Result.succ(1, "当前所选择的标本盒内有标本不能删除！", null);
        }
        Result result;
        LambdaUpdateWrapper<SamstoSpecbox> lambdaUpdateWrapper = new UpdateWrapper<SamstoSpecbox>().lambda();
        // set 表示要更新的字段， eq 表示  WHERE 条件
        lambdaUpdateWrapper.set(SamstoSpecbox::getDelFlag, 1)
                .in(SamstoSpecbox::getId, ids);
        this.baseMapper.update(new SamstoSpecbox(), lambdaUpdateWrapper);

        try {
            int b = this.baseMapper.update(new SamstoSpecbox(), lambdaUpdateWrapper);
            if (b > 0) {
                result = Result.succ(1, "删除成功", null);
            } else {
                result = Result.fail(400, "删除失败", "");
            }
        } catch (Exception e) {
            e.printStackTrace();
            result = Result.fail(400, "删除失败", "");
        }
        return result;
    }
}

